import axios from 'axios'

// 添加模拟数据
const mockAnnouncements = [
  {
    id: 1,
    title: '系统上线通知',
    content: '欢迎使用洗衣服务系统，系统已正式上线！',
    createTime: new Date().toISOString()
  },
  {
    id: 2,
    title: '春季优惠活动',
    content: '春季优惠活动来袭，下单即享8折优惠！',
    createTime: new Date().toISOString()
  }
];

export function getAnnouncements() {
  return axios.get('/api/announcement/list')
    .then(res => res.data)
    .catch(() => {
      // 如果API调用失败，返回模拟数据
      console.log('使用模拟数据');
      return {
        code: 200,
        message: '成功',
        data: mockAnnouncements
      };
    });
}

export function getAnnouncementById(id) {
  return axios.get(`/api/announcement/detail?id=${id}`).then(res => res.data)
}

export function createAnnouncement(data) {
  return axios.post('/api/announcement/create', data).then(res => res.data)
}

export function updateAnnouncement(data) {
  return axios.put('/api/announcement/update', data).then(res => res.data)
}

export function deleteAnnouncement(id) {
  return axios.delete(`/api/announcement/delete?id=${id}`).then(res => res.data)
} 